<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>水平居中布局解决方案2-margin-auto</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    #parent{
       width: 500px;
       height: 500px;
       background-color: red;
     }
     #child{
       /* 版心 - 居中 - 块级div + display:block 
        margin:上下  左右;
       */
       width: 300px;
       height: 300px;
       margin:0  auto;
       background-color: blue;
     }
  </style>
</head>

<body>
  <!-- 定义父级元素 -->
  <div id="parent">
    <!-- 定义子级元素 -->
    <div id="child"></div>
  </div>
</body>

</html>